<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<%@include file="/view/common/common.jsp"%>


	<script type="text/javascript">
		function searchData() {
			$('#tab').datagrid('load',serializeForm($('#mySearchForm')));
		}

		function edit() {
			$("#system_user_addDialog").form('clear')
			var rows = $('#tab').datagrid('getSelections');
			if (rows.length != 1) {
				$.messager.alert('消息', '请选择一条数据!', 'info');
				return false;
			}

			$("#system_user_addDialog").dialog({
				modal : true,
				iconCls : 'icon-edit',
				title : '充值',
				width : 300,
				cache : false,
				shadow:false,
				closed : false
			});


			$('#my_form').form('load',{
				userId:rows[0].user_id,
			});

		}
		
		function confineTradeCountToday(){
			var rows = $('#tab').datagrid('getSelections');
			if (rows.length != 1) {
				$.messager.alert('消息', '请选择一条数据!', 'info');
				return false;
			}
			$("#system_user_confineTradeCountDialog").form('clear')
			$("#system_user_confineTradeCountDialog").dialog({
				modal : true,
				iconCls : 'icon-edit',
				title : '限制交易次数',
				width : 300,
				cache : false,
				shadow:false,
				closed : false
			});
			$('#system_user_confineTradeCountDialog').form('load',{
				id:rows[0].user_id,
				count_trade:rows[0].count_trade
			});

		}



		function updatePwd(){
			var rows = $('#tab').datagrid('getSelections');
			if (rows.length != 1) {
				$.messager.alert('消息', '请选择一条数据!', 'info');
				return false;
			}
			$("#system_user_pwd").form('clear')
			$("#system_user_pwd").dialog({
				modal : true,
				iconCls : 'icon-edit',
				title : '修改会员密码',
				width : 300,
				cache : false,
				shadow:false,
				closed : false
			});
			$('#system_user_pwd').form('load',{
				id:rows[0].user_id
			});

		}
		
		
		function revise(flag) {
			var rows = $('#tab').datagrid('getSelections');
			if (rows.length != 1) {
				$.messager.alert('消息', '请选择一条数据!', 'info');
				return false;
			}
			if(flag == 1){
				$("#system_user_reviseDialog").form('clear')
	
				$("#system_user_reviseDialog").dialog({
					modal : true,
					iconCls : 'icon-edit',
					title : '充值矿晶矿场',
					width : 300,
					cache : false,
					shadow:false,
					closed : false
				});
	
	
				$('#my_reviseform').form('load',{
					id:rows[0].user_id,
				});
				
			}else{
				$("#system_user_phoneDialog").form('clear')
	
				$("#system_user_phoneDialog").dialog({
					modal : true,
					iconCls : 'icon-edit',
					title : '修改手机号码',
					width : 300,
					cache : false,
					shadow:false,
					closed : false
				});
	
	
				$('#my_phoneform').form('load',{
					id:rows[0].user_id,
					phone:rows[0].phone,
				});
			}


		}
		
		function confineTradeCountTodaySave(){
			var	url ='${ctx}/user/confineTradeCountSave.do';
			$("#my_confineTradeCountform").form('submit', {
				url : url,
				onSubmit : function() {
					if ($(this).form('validate') == false) {
						return false;
					}
					return true;
				},
				success : function(result) {
					var result = eval('(' + result + ')');
					if (result.isSuc) {
						$.messager.alert('消息', result.msg, 'info');
						$("#system_user_confineTradeCountDialog").dialog("close");
						$('#tab').datagrid('reload');
					} else {
						$.messager.alert('错误', result.msg, 'error');
					}
				}
			});
			
		}


		function doUpdatePwd(){
			var	url ='${ctx}/user/updatePwd.do';
			$("#my_user_pwd").form('submit', {
				url : url,
				onSubmit : function() {
					if ($(this).form('validate') == false) {
						return false;
					}
					return true;
				},
				success : function(result) {
					var result = eval('(' + result + ')');
					if (result.isSuc) {
						$.messager.alert('消息', result.msg, 'info');
						$("#system_user_pwd").dialog("close");
						$('#tab').datagrid('reload');
					} else {
						$.messager.alert('错误', result.msg, 'error');
					}
				}
			});

		}
		
		function reviSesave(flag) {
			var	url ='${ctx}/user/getUserRevise.do';
			if(flag == 1){
				$("#my_reviseform").form('submit', {
					url : url,
					onSubmit : function() {
						if ($(this).form('validate') == false) {
							return false;
						}
						return true;
					},
					success : function(result) {
						var result = eval('(' + result + ')');
						if (result.isSuc) {
							$.messager.alert('消息', result.msg, 'info');
							$("#system_user_reviseDialog").dialog("close");
							$('#tab').datagrid('reload');
						} else {
							$.messager.alert('错误', result.msg, 'error');
						}
					}
				});
			}else{
				$("#my_phoneform").form('submit', {
					url : url,
					onSubmit : function() {
						if ($(this).form('validate') == false) {
							return false;
						}
						return true;
					},
					success : function(result) {
						var result = eval('(' + result + ')');
						if (result.isSuc) {
							$.messager.alert('消息', result.msg, 'info');
							$("#system_user_phoneDialog").dialog("close");
							$('#tab').datagrid('reload');
						} else {
							$.messager.alert('错误', result.msg, 'error');
						}
					}
				});
			}
		}
		
		
		
		function saveOrUpDate() {
			var	url ='${ctx}/user/updateWallet.do';
			$("#my_form").form('submit', {
				url : url,
				onSubmit : function() {
					if ($(this).form('validate') == false) {
						return false;
					}
					return true;
				},
				success : function(result) {
					var result = eval('(' + result + ')');
					if (result.isSuc) {
						$.messager.alert('消息', result.msg, 'info');
						$("#system_user_addDialog").dialog("close");
						$('#tab').datagrid('reload');
					} else {
						$.messager.alert('错误', result.msg, 'error');
					}
				}
			});
		}
		
		function formatterChildCount(val, row) {
			if(val==0){
				return val;
			}else{
				return '<a href="javascript:;" onclick="showChild('+row.id+')">'+val+'</a>';
			}
		}
		function showChild(pid){
			$("#showChild_Dialog").dialog({
				modal : true,
				minimizable:true,
				maximizable:true,
				title : '直接下级',
				width: 1000,    
			    height: 400,  
				cache : false,
				shadow:false,
				closed : false
			});
			$('#showChild_Dialog').window('center');//使Dialog居中显示
			//加载数据
	        $('#Child_Table').datagrid({
	          url : '${ctx}/user/getChildUserByParentId.do?p_id='+pid,
	        });
		}
		
		function countTrade(val, row) {
			if (val == '' || val == null) {
				return '不限';
			}else{
				return val;
			}
		}
		
		function confinedTransfer(val, row) {
			if (val == '0') {
				return '不受限制';
			} else if(val == '1'){
				return '限制转账';
			}
		}

		function confinedTrade(val, row) {
			if (val == '0') {
				return '不受限制';
			} else if(val == '1') {
				return '限制买卖';
			}
		}
		
		function confinedState(val, row){
			if (val == '-1') {
				return '冻结';
			} else if(val == '1') {
				return '正常';
			}
		}
		
		function updateConfined(field,status) {
			var rows = $('#tab').datagrid('getSelections');
			if (rows.length != 1) {
				$.messager.alert('消息', '请选择一条数据!', 'info');
				return false;
			}
			if(field=='confined_transfer' &&  status ==0 && rows[0].confined_transfer==0){
				$.messager.alert('消息', '该用户已是解限状态!', 'info');return false;
			}
			if(field=='confined_transfer' &&  status ==1 && rows[0].confined_transfer==1){
				$.messager.alert('消息', '该用户已被限制转账!', 'info');return false;
			}
			if(field=='confined_trade' &&  status ==0 && rows[0].confined_trade==0){
				$.messager.alert('消息', '该用户已是解限状态!', 'info');return false;
			}
			if(field=='confined_trade' &&  status ==1 && rows[0].confined_trade==1){
				$.messager.alert('消息', '该用户已被限制买卖!', 'info');return false;
			}
			if(field=='confined_transfer' && status==1){
				$.messager.confirm('确认','您确认要对该用户进行限制转账吗？',function(r){    
				    if(r){    
				    	var url ='${ctx}/user/updateConfinedStatus.do';	
						$.post(url,{"id":rows[0].id,field:field,"status":status},function(result){
							var result = eval('(' + result + ')');
							if (result.isSuc) {
								$.messager.alert('消息', result.msg, 'info');
								$('#tab').datagrid('reload');
							} else {
								$.messager.alert('错误', result.msg, 'error');
							}
						}) 
				    }    
				});  
			}
			if(field=='confined_trade' && status==1){
				$.messager.confirm('确认','您确认要对该用户进行限制买卖吗？',function(r){    
				    if (r){    
				    	var url ='${ctx}/user/updateConfinedStatus.do';	
						$.post(url,{"id":rows[0].id,field:field,"status":status},function(result){
							var result = eval('(' + result + ')');
							if (result.isSuc) {
								$.messager.alert('消息', result.msg, 'info');
								$('#tab').datagrid('reload');
							} else {
								$.messager.alert('错误', result.msg, 'error');
							}
						}) 
				    }    
				});  
			}
			
			if(status==0){
				var url ='${ctx}/user/updateConfinedStatus.do';	
				$.post(url,{"id":rows[0].id,field:field,"status":status},function(result){
					var result = eval('(' + result + ')');
					if (result.isSuc) {
						$.messager.alert('消息', result.msg, 'info');
						$('#tab').datagrid('reload');
					} else {
						$.messager.alert('错误', result.msg, 'error');
					}
				}) 
			}
			
		}
		
		
	</script>

</head>
<body>

<div class="easyui-panel" fit="true">
	<div id="jqueryToolbar" style="padding:auto;height:auto">
		<div style="margin-top:5px; padding-bottom:8px; border-bottom:1px solid #ccc;">
			<form id="mySearchForm" action="" method="Post">
				手机:	<input type="text" id="phone" name="phone" class="easyui-textbox"  style="width: 100px; height: 25px;"/>
				uid:	<input type="text" id="uid"   name="uid"   class="easyui-textbox"  style="width: 100px; height: 25px;"/>
				<a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="searchData()">查询</a>
			</form>
		</div>
	</div>
	
	<div id="system_user_list_tb" style="height: auto; padding-left: auto;">
		<c:if test="${SESSION_INFO_OBJECT.type==0}">
			<a href="#" class="easyui-linkbutton" onclick="edit()" data-options="iconCls:'icon-edit',plain:true">充值</a>
			<a href="#" class="easyui-linkbutton" onclick="updateConfined('confined_transfer',1)" data-options="iconCls:'icon-lock',plain:true">限制转账</a>
			<a href="#" class="easyui-linkbutton" onclick="updateConfined('confined_transfer',0)" data-options="iconCls:'icon-ok',plain:true">解除限转</a>
			<a href="#" class="easyui-linkbutton" onclick="updateConfined('confined_trade',1)" data-options="iconCls:'icon-lock',plain:true">限制买卖</a>
			<a href="#" class="easyui-linkbutton" onclick="updateConfined('confined_trade',0)" data-options="iconCls:'icon-ok',plain:true">解除限卖</a>
			<a href="#" class="easyui-linkbutton" onclick="revise(0)" data-options="iconCls:'icon-ok',plain:true">修改手机号码</a>
			<a href="#" class="easyui-linkbutton" onclick="revise(1)" data-options="iconCls:'icon-edit',plain:true">充值矿晶矿场</a>
			<a href="#" class="easyui-linkbutton" onclick="confineTradeCountToday()" data-options="iconCls:'icon-edit',plain:true">限制当天交易次数</a>
			<a href="#" class="easyui-linkbutton" onclick="updatePwd()" data-options="iconCls:'icon-edit',plain:true">修改会员密码</a>
		</c:if>
	</div>
	<table id="tab" class="easyui-datagrid" fit="true" style="height:auto;width:auto;" url="${ctx}/user/getUser.do"
		   rownumbers="true" pagination="true" pagePosition="top" singleSelect="true"  toolbar="#system_user_list_tb">
		<thead>
		<tr>
			<th field="id"  width="80" align="center" style="display: none;">用户ID</th>
			<th field="nick_name"  width="80" align="center">昵称</th>
			<th field="phone" width="130" align="center">手机</th>
			<th field="uid" width="80" align="center">uid</th>
			<th field="invitation_code" width="85" align="center">邀请码</th>
			<th field="ifip" width="130" align="center">矿晶</th>
			<th field="ifiv" width="130" align="center">矿场</th>
			
			<th field="parent_nickname" width="130" align="center">推荐人</th>
			<th field="parent_phone" width="130" align="center">推荐人手机号</th>
			<th field="child_count" width="130" align="center" data-options="formatter:formatterChildCount" >直接下级</th>
			
			<th field="confined_transfer" width="80" align="center" data-options="formatter:confinedTransfer" >转账状态</th>
			<th field="confined_trade" width="80" align="center" data-options="formatter:confinedTrade" >买卖状态</th>
			<!-- <th field="state" width="80" align="center" data-options="formatter:confinedState" >买卖状态</th> -->
			<th field="count_trade" width="80" align="center" data-options="formatter:countTrade" >限制次数</th>
			<th field="create_time"  width="135" align="center">创建时间</th>
		</tr>
		</thead>
	</table>

	<div id="showChild_Dialog"  class="easyui-dialog"  data-options="closed:true">
	   <table id="Child_Table" class="easyui-datagrid" fit="true" style="height:auto;width:auto;" url="",  rownumbers="true" pagination="true" pagePosition="top" singleSelect="true" >
		<thead>
			<tr>
				<th field="id"  width="80" align="center" style="display: none;">用户ID</th>
				<th field="nick_name"  width="80" align="center">昵称</th>
				<th field="phone" width="130" align="center">手机</th>
				<th field="uid" width="80" align="center">uid</th>
				<th field="invitation_code" width="85" align="center">邀请码</th>
				<th field="ifip" width="130" align="center">矿晶</th>
				<th field="ifiv" width="130" align="center">矿场</th>
				<th field="create_time"  width="135" align="center">创建时间</th>
			</tr>
		</thead>
		</table>
	</div>

	<!-- 添加 ------------start -->
	<div id="system_user_addDialog"  class="easyui-dialog"  data-options="closed:true"  buttons="#addButs1">
		<form id="my_form" method="post">

			<input type="hidden" id="userId" name="userId"    >

			<table style="margin: 10px 20px;">
				<tr>
					<td style="text-align: right;">数量:</td>
					<td><input type="text" id="amount" name="amount"       style="width: 150px; height: 25px;" class="easyui-numberbox"  data-options="required:true,precision:4,missingMessage:'为必填项'" ></td>
				</tr>
				<tr>
					<td style="text-align: right;">交易密码:</td>
					<td><input type="text" id="trade_pwd" name="tradePwd"       style="width: 150px; height: 25px;" class="easyui-textbox"  data-options="required:true,missingMessage:'为必填项'" ></td>
				</tr>
			</table>
		</form>
		<div id="addButs1"  >
			<a href="#" class="easyui-linkbutton"   onclick="saveOrUpDate()"   style="width:80px;height:30px;" iconCls="icon-ok" >提交</a>
		</div>
	</div>
	<!-- 添加 ------------end -->
	
	<!-- 充值矿晶矿场------------end -->
	<div id="system_user_reviseDialog"  class="easyui-dialog"  data-options="closed:true"  buttons="#addButs2">
		<form id="my_reviseform" method="post">

			<input type="hidden" id="reviseId" name="id"    >

			<table style="margin: 10px 20px;">
				<tr>
					<td style="text-align: right;">矿晶:</td>
					<td><input type="text" id="ifip" name="ifip"       style="width: 150px; height: 25px;" class="easyui-numberbox"  data-options="required:true,precision:4,missingMessage:'为必填项'" ></td>
				</tr>
				<tr>
					<td style="text-align: right;">矿场:</td>
					<td><input type="text" id="ifiv" name="ifiv"       style="width: 150px; height: 25px;" class="easyui-numberbox"  data-options="required:true,precision:4,missingMessage:'为必填项'" ></td>
				</tr>
			</table>
		</form>
		<div id="addButs2"  >
			<a href="#" class="easyui-linkbutton"   onclick="reviSesave(1)"   style="width:80px;height:30px;" iconCls="icon-ok" >提交</a>
		</div>
	</div>
	
	<!-- 修改手机号码------------end -->
	<div id="system_user_phoneDialog"  class="easyui-dialog"  data-options="closed:true"  buttons="#addButs3">
		<form id="my_phoneform" method="post">

			<input type="hidden" id="phoneId" name="id"    >

			<table style="margin: 10px 20px;">
				<tr>
					<td style="text-align: right;">手机号码:</td>
					<td><input type="text" id="phone" name="phone"       style="width: 150px; height: 25px;" class="easyui-textbox"  data-options="required:true,missingMessage:'为必填项'" ></td>
				</tr>
			</table>
		</form>
		<div id="addButs3"  >
			<a href="#" class="easyui-linkbutton"   onclick="reviSesave(0)"   style="width:80px;height:30px;" iconCls="icon-ok" >提交</a>
		</div>
	</div>
	
	<!-- 修改限制交易次数 ------------end -->
	<div id="system_user_confineTradeCountDialog"  class="easyui-dialog"  data-options="closed:true"  buttons="#addButs4">
		<form id="my_confineTradeCountform" method="post">
			<input type="hidden" id="id" name="id" >
			<table style="margin: 10px 20px;">
				<tr>
					<td style="text-align: right;">次数:</td>
					<td><input type="text" id="count_trade" name="count_trade"  style="width: 150px; height: 25px;" class="easyui-numberbox"  data-options="missingMessage:'为必填项'" ></td>
				</tr>
			</table>
		</form>
		<div id="addButs4"  >
			<a href="#" class="easyui-linkbutton"   onclick="confineTradeCountTodaySave()"  style="width:80px;height:30px;" iconCls="icon-ok" >提交</a>
		</div>
	</div>


	<!-- 修改会员密码 ------------end -->
	<div id="system_user_pwd"  class="easyui-dialog"  data-options="closed:true"  buttons="#addButs4_user_pwd">
		<form id="my_user_pwd" method="post">
			<input type="hidden"  name="id" >
			<table style="margin: 10px 20px;">
				<tr>
					<td style="text-align: right;">会员密码:</td>
					<td>
						<input type="text"  name="pwd"  style="width: 150px; height: 25px;" class="easyui-textbox"  data-options="" >
					</td>
				</tr>
				<tr>
					<td style="text-align: right;">交易密码:</td>
					<td>
						<input type="text"  name="trade_pwd"  style="width: 150px; height: 25px;" class="easyui-textbox"  data-options="" >
					</td>
				</tr>

			</table>
		</form>
		<div id="addButs4_user_pwd"  >
			<a href="#" class="easyui-linkbutton"   onclick="doUpdatePwd()"  style="width:80px;height:30px;" iconCls="icon-ok" >提交</a>
		</div>
	</div>

</div>
</body>
</html>
